package com.rou.im.framework.core.processorstack.processor;

import com.rou.im.framework.core.Request;
import com.rou.im.framework.core.context.RequestContext;
import com.rou.im.framework.core.processorstack.Processor;
import com.rou.im.framework.core.context.RequestContextHolder;
import com.rou.im.framework.core.processorstack.StackInvocation;

/**
 * <p>
 *     RequestContext的一个生命周期助手，默认的第一个助手
 * </p>
 *
 * @author GaoShuangWen
 * @since 2020-04-29 10:18
 */
public class RequestContextPersistenceProcessor implements Processor {

    @Override
    public void process(Request request, StackInvocation invocation) {
        RequestContext context = RequestContextHolder.getContext();
        try {
            // 初始化
            context.setRequest(request);
            invocation.invoke(request);
        }finally {
            RequestContextHolder.clearContext();
        }

    }
}
